# 哈希超时
# class Solution(object):
#     def checkPalindromeFormation(self, a, b):
#         n = len(a)
#         base = 10 ** 9 + 7
#         pre_a = 0
#         pre_b = 0
#         suff_a = 0
#         suff_b = 0
#         for i in range(n):
#             pre_a = (pre_a * 26 + ord(a[i]) - ord('a')) % base
#             pre_b = pre_b * 26 + ord(b[i]) - ord('a') % base
#             suff_a = (suff_a * 26 + ord(a[n - 1 - i]) - ord('a')) % base
#             suff_b = (suff_b * 26 + ord(b[n - 1 - i]) - ord('a')) % base
#         if (pre_a == suff_a and a == a[::-1]) or (pre_b == suff_b and b == b[::-1]):
#             return True
#         for i in range(n - 1):
#             pre_a = (pre_a - (ord(a[n - 1 - i]) - ord('a')) * pow(26, i, base) + (ord(b[n - 1 - i]) - ord('a')) * pow(
#                 26, i, base)) % base
#             pre_b = (pre_b - (ord(b[n - 1 - i]) - ord('a')) * pow(26, i, base) + (ord(a[n - 1 - i]) - ord('a')) * pow(
#                 26, i, base)) % base
#             suff_a = (suff_a - (ord(a[n - 1 - i]) - ord('a')) * pow(26, n - 1 - i, base) + (
#                         ord(b[n - 1 - i]) - ord('a')) * pow(26, n - 1 - i, base)) % base
#             suff_b = (suff_b - (ord(b[n - 1 - i]) - ord('a')) * pow(26, n - 1 - i, base) + (
#                     ord(a[n - 1 - i]) - ord('a')) * pow(26, n - 1 - i, base)) % base
#             if pre_a == suff_a:
#                 t = a[: n - 1 - i] + b[n - 1 - i:]
#                 if t == t[::-1]:
#                     return True
#             if pre_b == suff_b:
#                 t = b[: n - 1 - i] + a[n - 1 - i:]
#                 if t == t[::-1]:
#                     return True
#         return False

class Solution(object):
    def checkPalindromeFormation(self, a, b):
        n = len(a)
        flag = True
        for i in range(n // 2):
            if a[i] == b[n - 1 - i]:
                continue
            else:
                if a[i: n - i] == a[i: n - i][::-1] or b[i: n - i] == b[i: n - i][::-1]:
                    return True
                else:
                    flag = False
                    break
        if flag:
            return True
        flag = True
        for i in range(n // 2):
            if b[i] == a[n - 1 - i]:
                continue
            else:
                if b[i: n - i] == b[i: n - i][::-1] or a[i: n - i] == a[i: n - i][::-1]:
                    return True
                else:
                    flag = False
                    break
        if flag:
            return True
        return False


data = Solution()
a = "xbdef"
b = "xecab"
print(data.checkPalindromeFormation(a, b))
